package clog

import (
	"gitee.com/cooge/impush/config"
	log "github.com/sirupsen/logrus"
	"io"
	"os"
	"path/filepath"
)

func Init(open bool) {

	tf := &log.TextFormatter{}
	tf.TimestampFormat = "2006-01-02 15:04:05"
	log.SetFormatter(tf)

	if open {
		log.SetLevel(log.DebugLevel)
	} else {
		log.SetLevel(log.InfoLevel)
	}

	path := config.LOG_PATH
	if len(path) > 0 {
		err := os.MkdirAll(path, 0777)
		if err == nil {
			path = path + "/test.log"
			file1, err := os.Create(path)
			if err == nil {
				apath, err := filepath.Abs(path)
				if err == nil {
					log.Info("日志保存路径", apath)
					log.SetOutput(io.MultiWriter(file1, os.Stdout))
				}
			}
		}
	}
}
